package com.icode.jfinal;

import com.icode.model.User;
import com.icode.web.controller.IndexController;
import com.icode.web.controller.UserFormController;
import com.icode.web.controller.UsersController;
import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

/**
 * User: alexz
 * Date: 14-11-7
 * Time: 下午4:08
 */
public class JFinalConfiguration extends JFinalConfig {

    @Override
    public void configConstant(Constants me) {
        me.setViewType(ViewType.JSP);
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/", IndexController.class);
        me.add("/index", IndexController.class);
        me.add("/users", UsersController.class);
        me.add("/user/form", UserFormController.class);
    }

    @Override
    public void configPlugin(Plugins me) {
        String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/template?useUnicode=true&characterEncoding=UTF-8";
        String username = "root";
        String password = "root";
        C3p0Plugin mysqlDataSource = new C3p0Plugin(jdbcUrl, username, password);
        mysqlDataSource.setDriverClass("com.mysql.jdbc.Driver");
        me.add(mysqlDataSource);

        ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin("mysql", mysqlDataSource);
        me.add(activeRecordPlugin);

        activeRecordPlugin.addMapping("user", User.class);
    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {

    }
}
